import sys
import requests

if sys.argv[1] == "-j":
        req = requests.get(f"https://api.mcsrvstat.us/2/{sys.argv[2]}")
        reg = req.json()
        drtyh = reg['debug']


        if reg['online'] is True:
            ret = reg['players']
    
            print("Server is online.")
            print(f"{ret['online']}/{ret['max']} players online.")
            print(f"IP and Port is \"{reg['ip']}:{reg['port']}\".")
            print(f"Server version is \"{reg['version']}\".")
            if drtyh['srv'] is True:
                print(f"Hostname is \"{reg['hostname']}\".")
            else:
                print(f"This server doesn't have hostname.")
            print(f"Icon: https://api.mcsrvstat.us/icon/{sys.argv[2]}")
            print(f"Web (more info): https://mcsrvstat.us/server/{sys.argv[2]}")
        else:
            print(f"Server is offline.")
elif sys.argv[1] == "-b":
        breq = requests.get(f"https://api.mcsrvstat.us/bedrock/2/{sys.argv[2]}")
        breg = breq.json()
        # bdebug = breg['debug']

        if breg['online'] is True:
            bret = breg['players']

            print("Server is online.")
            print(f"{bret['online']}/{bret['max']} players online.")
            print(f"IP and Port is \"{breg['ip']}:{breg['port']}\".")
            print(f"Server version is \"{breg['version']}\".")
            print(f"Hostname is \"{breg['hostname']}\".")
            print(f"Icon: https://api.mcsrvstat.us/icon/{sys.argv[2]}")
            print(f"Web (more info): https://mcsrvstat.us/bedrock/server/{sys.argv[2]}")
        else:
            print("Server is offline.")
elif sys.argv[1] != ["-j","-b"]:
    print("Incorrect usage.")
    print(f"Usage: {sys.argv[0]} (Server type) (Server IP)")
    print("Server types:")
    print("-j Java server type")
    print("-b Bedrock server type")

